package com.zxp.cloud.storage.controller;

import com.zxp.cloud.core.api.ResponseData;
import com.zxp.cloud.core.api.SuccessResponseData;
import com.zxp.cloud.storage.model.Storage;
import com.zxp.cloud.storage.service.StorageService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * @author shollin
 * @desc
 * @date 2021/7/18/018 9:40
 */
@RestController
@RequiredArgsConstructor
@Slf4j
@RefreshScope
public class StorageController {

    @Value("${author:}")
    public String author;

    private final RestTemplate restTemplate;
    private final StorageService storageService;


    @GetMapping("/")
    public String index(){
        return "order hello:"+author;
    }

    @PostMapping("/save")
    public Storage save(@RequestBody Storage storage){
        return storageService.save(storage);

    }

    @RequestMapping("/descrement")
    public ResponseData descrement(@RequestParam("productId") Long productId, @RequestParam("count") Integer count){
        Storage storage = storageService.descrement(productId, count);

        return new SuccessResponseData(storage);
    }
}
